Skip to content

[Fix][Core] Build the plugin classloader URL array without a null entry - #13367

Merged
nzw921rx merged 3 commits into
apache:devfrom
corgy-w:fix/plugin-discovery-url-null
Dec 1, 2026
Merged

nzw921rx merged 3 commits into
apache:devfrom
corgy-w:fix/plugin-discovery-url-null

Conversation

@corgy-w

@corgy-w corgy-w commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

What

AbstractPluginDiscovery.createOptionalPluginInstance builds a URL[] with one slot too many before constructing the fallback URLClassLoader:

URL[] urls = new URL[pluginJars.size() + 1];
int i = 0;
for (URL pluginJar : pluginJars) {
    urls[i++] = pluginJar;
}
urls = Stream.concat(Arrays.stream(urls), pluginJarPaths.get().stream()).distinct().toArray(URL[]::new);
classLoader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());

The extra slot is never filled, distinct()/toArray() keep the null, and URLClassLoader's internal URLClassPath adds every URL to an ArrayDeque, which rejects null, so the constructor always throws.

This is not an edge case on JDK 9+: AppClassLoader is not a URLClassLoader, so the default DEFAULT_URL_TO_CLASSLOADER consumer throws UnsupportedOperationException, meaning the catch block is always reached and the fallback always NPEs.

Verified on JDK 11 with the buggy code:

java.lang.NullPointerException
    at java.base/java.util.ArrayDeque.addLast(ArrayDeque.java:304)
    at java.base/java.util.ArrayDeque.add(ArrayDeque.java:495)
    at java.base/jdk.internal.loader.URLClassPath.<init>(URLClassPath.java:155)
    at java.base/jdk.internal.loader.URLClassPath.<init>(URLClassPath.java:172)
    at java.base/java.net.URLClassLoader.<init>(URLClassLoader.java:120)
    at org.apache.seatunnel.plugin.discovery.AbstractPluginDiscovery.createOptionalPluginInstance(AbstractPluginDiscovery.java:249)

Fix

Build the array directly from the two streams, so no null entry can appear:

URL[] urls =
        Stream.concat(additionalPluginJars.stream(), pluginJarPaths.get().stream())
                .distinct()
                .toArray(URL[]::new);
classLoader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());

Everything else (logging, ordering, the loadPluginInstance call) is unchanged.

Rename (no behaviour change)

pluginJars was ambiguous because the class also has the discovered pluginJarPaths: the parameter actually means extra jars the caller passes in. It is renamed to additionalPluginJars in:

  • PluginDiscovery (both interface methods, with the javadoc now saying these are additional jars used to help the plugin load, as opposed to the jars discovered from the plugin directory),
  • AbstractPluginDiscovery (the override, the internal (List<URL>) cast and createPluginInstance(...), which forwards its own parameter).

git grep createOptionalPluginInstance across the tree shows AbstractPluginDiscovery is the only implementation. No method name, signature or type is changed; parameter names are not part of the API/binary contract, so this is source- and binary-compatible.

Test

AbstractPluginDiscoveryTest#testCreateOptionalPluginInstanceFallbackWithoutUrlClassLoader (added to the existing test class, no new test class):

  • builds a plugin dir containing a connector-fallback.jar, plus an additional jar that carries a META-INF/services descriptor for a test plugin,
  • sets the thread context classloader to a plain ClassLoader (not a URLClassLoader) delegating to the test classloader, so the default consumer throws and the catch block executes,
  • asserts the plugin instance is still created by the fallback URLClassLoader and is the expected implementation.

Red (old implementation restored, -DtrimStackTrace=false): the new test errors with the URLClassPath.<init> NPE quoted above.

Green after the fix, ./mvnw -o -pl seatunnel-plugin-discovery test -Dskip.spotless=true:

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.307 s - in org.apache.seatunnel.plugin.discovery.AbstractPluginDiscoveryTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.034 s - in org.apache.seatunnel.plugin.discovery.seatunnel.SeaTunnelSourcePluginDiscoveryTest
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

./mvnw -o -q -pl seatunnel-plugin-discovery spotless:apply was run before the final test run.

Compatibility

No public API, signature, method name or type changes; only the fallback array construction is fixed and a parameter name is clarified.

@github-actions github-actions Bot added the core SeaTunnel core module label Nov 19, 2026

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing to Apache SeaTunnel! I reviewed the complete current diff and followed its entry points and failure paths. I did not find a source-level merge blocker in the reviewed paths.

What problem does this PR solve?

User pain: a connector absent from the context classpath cannot load when the existing classloader rejects URL injection. Fix: concatenate the caller jars and discovered plugin jars directly, without the unused null slot. In one sentence: the fallback loader receives only real jar URLs. Example: a JDK 17 application classloader can fall back to loading a connector from the plugins directory instead of throwing NullPointerException.

1. Code changes

1.1 Core logic

Complete runtime path:

Starter plugin discovery -> createPluginInstance / createOptionalPluginInstance
 -> load from context classloader (unchanged fast path)
 -> resolve plugin directory jars -> try URL injection
 -> injection throws -> concatenate additional and discovered URL streams -> URLClassLoader
 -> ServiceLoader resolves plugin -> caller uses Source/Sink/Transform

Key findings and correctness:

The normal already-visible-plugin path is unchanged. The fix is reached only when discovery found a plugin jar and injection into the context loader fails (AbstractPluginDiscovery.java:226-246). The old additional-jars-sized array always retained a null slot, even for no additional jars; URLClassLoader rejects it. The new stream preserves additional-before-discovered ordering and distinct URLs. The Collection parameter rename changes no JVM signature. The fallback loader lifetime is pre-existing design, not resolved by this URL-array fix.

Before:


    @Override
    public Optional<T> createOptionalPluginInstance(
            PluginIdentifier pluginIdentifier, Collection<URL> pluginJars) {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        T pluginInstance = loadPluginInstance(pluginIdentifier, classLoader);
        if (pluginInstance != null) {

After:


    @Override
    public Optional<T> createOptionalPluginInstance(
            PluginIdentifier pluginIdentifier, Collection<URL> additionalPluginJars) {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        T pluginInstance = loadPluginInstance(pluginIdentifier, classLoader);
        if (pluginInstance != null) {

1.2 Compatibility

Fully compatible at the existing configuration and row-contract level; no option rename, protocol change, default change, or new dependency is introduced.

1.3 Performance and side effects

The change remains in the affected component. It introduces no per-row global lock, unbounded data buffer, or new network dependency; exceptional-path costs and resource ownership are discussed above.

1.4 Errors, logging, and findings

Issue 1: Isolate fallback test artifacts and narrow cleanup suppression

  • Location: seatunnel-plugin-discovery/src/test/java/org/apache/seatunnel/plugin/discovery/AbstractPluginDiscoveryTest.java:170.
  • Description and risk: The new test uses a fixed target/fallback-plugin directory and suppresses every FileSystemException, although the comment promises to suppress only the Windows jar-lock case. Parallel/repeated invocations can share these paths, and access-denied or directory errors can be silently hidden. This is a test-isolation risk, not evidence of a production loading failure.
  • Best improvement: Use a per-test temporary directory and an explicit loader/resource cleanup strategy; if a platform lock must be tolerated, constrain the suppressed condition rather than all FileSystemException values.
  • Responsibility and trade-off: The root cause is generic fallback URL assembly in AbstractPluginDiscovery.createOptionalPluginInstance, so the shared discovery layer is the correct and smallest complete fix. A connector-specific workaround cannot repair a null array for every plugin. Keep SPI identity, mappings and the normal injection path unchanged.
  • Severity: Medium; blocking: false.
  • Previously raised by another reviewer: No, unless explicitly attributed above.

Community input: no independent technical finding or maintainer approval/change request was present in the collected discussion.

2. Code quality

2.1 Conventions

Reviewed all changed files for license, imports, naming, core-method and state-field comments. See the numbered findings for the required changes.

2.2 Test coverage and stability

Stability rating: At risk. AbstractPluginDiscoveryTest.java:102-145 installs a non-URL context loader and a real service-descriptor jar; the plugin-name and class assertions fail on the old null-array implementation. The finally block restores the context loader, and AfterEach restores Common globals. No sleep, clock-dependent assertion, port, network or ordering requirement is introduced. The fixed target directory and best-effort Windows cleanup deserve the non-blocking improvement below.

2.3 Documentation

No option, default, plugin registration, artifact mapping or user command changes; bilingual connector reference changes are not required for this internal loader correction.

3. Architecture

3.1 Change location

The root cause is generic fallback URL assembly in AbstractPluginDiscovery.createOptionalPluginInstance, so the shared discovery layer is the correct and smallest complete fix. A connector-specific workaround cannot repair a null array for every plugin. Keep SPI identity, mappings and the normal injection path unchanged.

3.2 Maintainability

Keep the behavior, lifecycle ownership, and failure contract together. The root cause is generic fallback URL assembly in AbstractPluginDiscovery.createOptionalPluginInstance, so the shared discovery layer is the correct and smallest complete fix. A connector-specific workaround cannot repair a null array for every plugin. Keep SPI identity, mappings and the normal injection path unchanged.

3.3 Extensibility

Prefer the existing component boundary and tests over unrelated shared abstractions.

3.4 Upgrade impact

Fully compatible at the existing configuration and row-contract level; no option rename, protocol change, default change, or new dependency is introduced.

4. Findings summary

# Finding Location Severity
1 Isolate fallback test artifacts and narrow cleanup suppression seatunnel-plugin-discovery/src/test/java/org/apache/seatunnel/plugin/discovery/AbstractPluginDiscoveryTest.java:170 Medium

5. Merge recommendation

Can merge once the recorded CI and repository gates are satisfied

Blocking items: No source blocker. Current-head CI and write-capable maintainer review remain independent requirements.

Non-blocking suggestions: Issue 1: Isolate fallback test artifacts and narrow cleanup suppression

Overall: the reviewed source path is coherent; no runtime acceptance is claimed beyond the actual CI result. Daniel has READ permission, so this COMMENT cannot dismiss historical requested changes or satisfy a write-capable maintainer approval gate.

CI and repository state: Signal pull request update: SUCCESS; Build: FAILURE; Build: in_progress. GitHub reports BLOCKED / REVIEW_REQUIRED.

Verification: Reviewed all changed files and the referenced call sites at f92bd613d43ac55835604fdde0a8acb3787bf941 against merge base 1d0e6509a0aba3e34219a1a7ae370913f0150b2a. git diff --check passed. I did not build, run tests, or execute SeaTunnel locally.

Review time: 2026-11-20T06:35:12.509561-05:00

Local evidence: git fetch obtained head f92bd613d43ac55835604fdde0a8acb3787bf941; git merge-base returned 1d0e6509a0aba3e34219a1a7ae370913f0150b2a; git diff --stat reports 3 files changed, 136 insertions(+), 16 deletions(-). git show and source searches were used for the entry points above. No local build, unit test, E2E, Docker run or service startup was executed.

CI: Apache currently retains a failing Build result while the exact-head fork Build is already in progress. Please let that existing attempt finish; no additional retry is needed now. These states are not a passing runtime result.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! I re-reviewed the complete latest diff and the plugin-loading path. The production correction remains sound; the earlier nonblocking test-isolation suggestion is unchanged. The current Build is in progress, so I am keeping source clearance separate from completed CI.

What problem does this PR solve?

User pain: fallback plugin loading throws NullPointerException when URL injection is unavailable.

Fix: concatenate additional jars and discovered plugin jars directly, removing the unused null array slot.

In one sentence: a non-URL context loader can reach the existing plugin-directory fallback. Example: a JDK 17 application loader that cannot be mutated can still load the requested connector through a child URLClassLoader.

1. Code changes

1.1 Core logic

Complete runtime path:

Starter/Factory plugin request -> createPluginInstance -> createOptionalPluginInstance (AbstractPluginDiscovery.java:218)
 -> loadPluginInstance(context loader) -> return if already visible
 -> getPluginJarPath -> attempt existing URL injection
 -> exception -> concatenate additional URLs then discovered URLs; distinct -> URLClassLoader (:239-244)
 -> ServiceLoader/plugin identity resolution -> Optional instance or existing not-found failure

Key findings and correctness:

  • I re-read all three changed files at this new head. Normal classpath hits and successful URL injection are unchanged; only the injection-failure branch receives the corrected array.
  • The old additional-jars-sized-plus-one array necessarily included null; concatenating its elements carried that null into URLClassLoader. The new stream produces exactly the supplied/discovered URLs, retaining order and de-duplication.
  • Parameter renaming changes no JVM signature or SPI contract. Plugin mappings, service identities and artifact distribution are unchanged.
  • My earlier nonblocking test-isolation concern is still present; it is carried forward below, not a new blocker. The fallback loader lifetime is inherited behavior outside this null-array fix.

Before:

URL[] urls = new URL[pluginJars.size() + 1];
// the unused last element was concatenated into the fallback URLs

After:

URL[] urls = Stream.concat(additionalPluginJars.stream(), pluginJarPaths.get().stream())
    .distinct().toArray(URL[]::new);

1.2 Compatibility

Fully compatible: existing plugin SPI signatures, mappings, option names/defaults and row/checkpoint formats are unchanged. The renamed parameter is source documentation only.

1.3 Performance and side effects

One intermediate URL array is removed on an exceptional startup path. No per-row work, lock, retry, network call or buffer is added. The pre-existing child classloader ownership is unchanged, with the remaining Windows file lock exposed by the new test.

1.4 Errors, logging, and findings

Issue 1: Isolate fallback test artifacts and narrow cleanup suppression

  • Location: seatunnel-plugin-discovery/src/test/java/org/apache/seatunnel/plugin/discovery/AbstractPluginDiscoveryTest.java:170.
  • Description and risk: As in my previous review, the test shares target/fallback-plugin across invocations and deleteIfPossible suppresses every FileSystemException, although its contract only describes the Windows open-jar lock case. A parallel/repeated invocation can share files, and permission/path errors can be hidden. This is a test-isolation concern, not a new production source blocker.
  • Best improvement: Prefer a per-test temporary directory, and limit any tolerated cleanup failure to the documented platform condition. Keep the exact plugin assertions and context-loader restoration.
  • Responsibility and trade-off: The null originates in AbstractPluginDiscovery.createOptionalPluginInstance, so generic discovery is the best and smallest complete fix. Connector-specific changes cannot remove it for all plugins; changing caller classloaders would widen scope. Retain the existing injection fast path and fix only fallback assembly.
  • Severity: Medium; blocking: false.
  • Previously raised by another reviewer: No, unless explicitly attributed above.

Community input: no independent technical finding or maintainer approval/change request was present in the collected discussion.

2. Code quality

2.1 Conventions

Reviewed all changed files for license, imports, naming, core-method and state-field comments. See the numbered findings for the required changes.

2.2 Test coverage and stability

Stability rating: Stable. AbstractPluginDiscoveryTest.java:102 creates a real service-descriptor jar, installs a non-URL context loader, and checks the exact plugin class/name. Removing the production URL-array correction makes that path fail. TCCL/Common settings are restored. Stability: At risk, limited to the fixed shared artifact directory and overly broad FileSystemException suppression described in Issue 1; no timing/network/port or ordering assertion was introduced.

2.3 Documentation

No user-facing option or installation command changes; the PluginDiscovery interface now clarifies additional caller jars versus discovered plugin jars. No bilingual connector guide change is needed.

3. Architecture

3.1 Change location

The null originates in AbstractPluginDiscovery.createOptionalPluginInstance, so generic discovery is the best and smallest complete fix. Connector-specific changes cannot remove it for all plugins; changing caller classloaders would widen scope. Retain the existing injection fast path and fix only fallback assembly.

3.2 Maintainability

Keep the behavior, lifecycle ownership, and failure contract together. The null originates in AbstractPluginDiscovery.createOptionalPluginInstance, so generic discovery is the best and smallest complete fix. Connector-specific changes cannot remove it for all plugins; changing caller classloaders would widen scope. Retain the existing injection fast path and fix only fallback assembly.

3.3 Extensibility

Prefer the existing component boundary and tests over unrelated shared abstractions.

3.4 Upgrade impact

Fully compatible: existing plugin SPI signatures, mappings, option names/defaults and row/checkpoint formats are unchanged. The renamed parameter is source documentation only.

4. Findings summary

Completeness check: All changed files and affected entry/failure paths were reviewed; configuration/serialization compatibility, test failure capability and stability, documentation/examples, change ownership, and current CI/conflict/review gates are covered above. No unreviewed source scope is claimed complete.

# Finding Location Severity
1 Isolate fallback test artifacts and narrow cleanup suppression seatunnel-plugin-discovery/src/test/java/org/apache/seatunnel/plugin/discovery/AbstractPluginDiscoveryTest.java:170 Medium

5. Merge recommendation

Can merge once the recorded CI and repository gates are satisfied

Blocking items: No source blocker. Current-head CI and write-capable maintainer review remain independent requirements.

Non-blocking suggestions: Issue 1: Isolate fallback test artifacts and narrow cleanup suppression

Overall: the reviewed source path is coherent; no runtime acceptance is claimed beyond the actual CI result. Daniel has READ permission, so this COMMENT cannot dismiss historical requested changes or satisfy a write-capable maintainer approval gate.

CI and repository state: Signal pull request update: SUCCESS; Build: IN_PROGRESS; Build: queued. GitHub reports BLOCKED / REVIEW_REQUIRED.

Verification: Reviewed all changed files and the referenced call sites at cd1b228b9697cbc171ca870093a00124483fc7a2 against merge base 1d0e6509a0aba3e34219a1a7ae370913f0150b2a. git diff --check passed. I did not build, run tests, or execute SeaTunnel locally.

Review time: 2026-11-21T06:33:43.465040-05:00

Local evidence: git fetch obtained head cd1b228b9697cbc171ca870093a00124483fc7a2; git merge-base returned 1d0e6509a0aba3e34219a1a7ae370913f0150b2a; git diff --stat reports 3 files changed, 136 insertions(+), 16 deletions(-). git show and source searches were used for the entry points above. No local build, unit test, E2E, Docker run or service startup was executed.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for following this through! The previous complete review had no remaining source blocker and was waiting only for CI/repository gates. Both Apache Build and the exact-head fork Build have now succeeded, so I am clearing that prior CI-only blocker and changing this review to approve. This is an unchanged-head CI follow-up, not a second full source review.

Exact-head Build is completed with success. No failing or pending checks appear in the current Apache rollup. Previous Daniel conclusion remains the source-review reference.

5. Merge recommendation

Conclusion: Can merge from the recorded technical review perspective, subject to independent repository approval

  1. Blocking items: No remaining source or CI blocker from the previous Daniel review. The effective write-capable maintainer approval/dismissal gate is separate; this review does not bypass it.

  2. Non-blocking suggestions: Any explicitly non-blocking items in the previous full review remain optional and unchanged.

Overall assessment and alternatives: No further source patch or upstream sync is requested solely to chase the old CI state. Keep the reviewed implementation; an unrelated workaround would expand scope.

Snapshot: unchanged head cd1b228b9697cbc171ca870093a00124483fc7a2; base dev; compare diverged, ahead_by=3, behind_by=15; GitHub BLOCKED / REVIEW_REQUIRED. Drift is recorded independently and does not justify a sync request here. Daniel has READ repository permission: a submitted technical APPROVED record cannot satisfy the effective write-reviewer requirement or dismiss historical requested changes. No local build, test or runtime execution was performed.

@nzw921rx nzw921rx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 LGTM

@nzw921rx
nzw921rx added this pull request to the merge queue Dec 1, 2026
Merged via the queue into apache:dev with commit 4f7ca9f Dec 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core SeaTunnel core module reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants